﻿$(document).ready(function () {
    $(".hidden").hide();
    $(".hidden_new").hide();
    $(".showInfor_RoomType").click(function () {
        $("#info_" + $(this).attr("id")).toggle("slow");
    })

    $("#btn_add_room").click(function () {
        $("#info_new").toggle("slow");
    })

    $(".update").live("click", function () {
        var maLoai = $(this).attr("id");
        var moTa = $("#moTa" + maLoai).val();
        var soLuong = $("#soLuong" + maLoai).val();
        var tenLoai = $("#tenLoai" + maLoai).val();
        var dataString =  "moTa=" + moTa + "&soLuong=" + soLuong + "&maLoai=" + maLoai + "&tenLoai=" + tenLoai
        $.ajax({
            type: "GET",
            url: "Update_RoomType",
            data: dataString,
            dataType: 'html',
            success: function (data) {
                $("#notice" + maLoai).html(data).hide().fadeIn();
                setTimeout(function () {
                    $("#notice" + maLoai).fadeOut("slow", function () {
                        //$("#notice" + maLoai).remove();
                    });
                }, 2000);
            }
        });
    });


    $(".delete").live("click", function () {
        var maLoai = $(this).attr("id");
        var dataString = "maLoai" + maLoai;
        maLoai = maLoai.substr(1);
        $.ajax({
            type: "GET",
            url: "Delete_RoomType",
            data: dataString,
            dataType: 'html',
            success: function (data) {
                $("#notice_" + maLoai).html(data).show();
                setTimeout(function () {
                    $("#notice_" + maLoai).fadeOut("slow", function () {
                        //$("#notice" + maLoai).remove();
                    });
                }, 2000);
                location.reload();
            }
        });
    });


    $(".add").live("click", function () {
        var maLoai = "_new";
        var moTa = $("#moTa" + maLoai).val();
        var soLuong = $("#soLuong" + maLoai).val();
        var tenLoai = $("#tenLoai" + maLoai).val();
        var dataString = "moTa=" + moTa + "&soLuong=" + soLuong  + "&tenLoai=" + tenLoai
        $.ajax({
            type: "GET",
            url: "Add_RoomType",
            data: dataString,
            dataType: 'html',
            success: function (data) {
                $("#notice" + maLoai).html(data).show()
                setTimeout(function () {
                    $("#notice" + maLoai).fadeOut("slow", function () {
                        //$("#notice" + maLoai).remove();
                    });
                }, 2000);
                location.reload();
            }
        });
    });


});